<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width=" ">
      <!-- <el-form-item label="活动id" prop="activityId">
        <el-input v-model="queryParams.activityId" placeholder="请输入活动id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="活动名称" prop="activityName">
        <el-input v-model="queryParams.activityName" placeholder="请输入活动id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="用户id" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="用户昵称" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="报名时间" prop="applyTime">
        <el-date-picker clearable v-model="queryParams.applyTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择报名时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="参与时间" prop="participateTime">
        <el-date-picker clearable v-model="queryParams.participateTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择参与时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="删除标识" prop="isDel">
        <template slot="label">
          <span>
            删除标识
            <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
        </template>
        <el-input v-model="queryParams.isDel" clearable placeholder="请输入删除标识" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="减少CO2" prop="reduceCo2">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.reduceCo2"-->
      <!--          placeholder="请输入减少CO2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="获得积分" prop="earnPoints">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.earnPoints"-->
      <!--          placeholder="请输入获得积分"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="是否删除" prop="isDel">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.isDel"-->
      <!--          placeholder="请输入是否删除"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段1" prop="ext1">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext1"-->
      <!--          placeholder="请输入扩展字段1"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段2" prop="ext2">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext2"-->
      <!--          placeholder="请输入扩展字段2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段3" prop="ext3">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext3"-->
      <!--          placeholder="请输入扩展字段3"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段4" prop="ext4">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext4"-->
      <!--          placeholder="请输入扩展字段4"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段5" prop="ext5">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext5"-->
      <!--          placeholder="请输入扩展字段5"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
    </el-form>

    <el-row :gutter="10" class="mb8" style="display: flex;">
      <el-col style="justify-content: left;" :span="20">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:activityLogs:add']">新增</el-button>
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:activityLogs:edit']">修改</el-button>
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:activityLogs:remove']">删除</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:activityLogs:export']">导出</el-button>
      </el-col>
      <el-col style="justify-content: right;" class="text-right" v-show="showSearch" :span="2.5">
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :span="1.5"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="activityLogsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="活动参与id" align="center" prop="participateId" />
      <!-- <el-table-column label="活动id" align="center" prop="activityId" /> -->
      <el-table-column label="活动名称" align="center" prop="activityName" />
      <!-- <el-table-column label="用户id" align="center" prop="userId" /> -->
      <!-- <el-table-column label="用户真实姓名" align="center" prop="realName" /> -->
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <!-- <el-table-column label="报名时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
</el-table-column> -->
      <el-table-column label="参与地点" align="center" prop="participatePosition" />
      <el-table-column align="center" label="打卡图片" prop="punchingImg" width="100">
        <template slot-scope="scope">
          <p v-if="scope.row.punchingImg == null">无图片</p>
          <image-preview v-if="scope.row.punchingImg != null" :src="scope.row.punchingImg" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="参与时间" align="center" prop="participateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.participateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="获得减碳量" align="center" prop="reduceCo2" />
      <el-table-column label="获得积分" align="center" prop="earnPoints" />
      <el-table-column label="删除标识" align="center" prop="isDel" />
      <!--      <el-table-column label="扩展字段1" align="center" prop="ext1" />-->
      <!--      <el-table-column label="扩展字段2" align="center" prop="ext2" />-->
      <!--      <el-table-column label="扩展字段3" align="center" prop="ext3" />-->
      <!--      <el-table-column label="扩展字段4" align="center" prop="ext4" />-->
      <!--      <el-table-column label="扩展字段5" align="center" prop="ext5" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="更新时间" align="center" prop="updateTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-hasPermi="['monitor:job:query']">详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改活动参与记录管理对话框 -->
    <el-dialog :title="title" :visible.sync="openEdit" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="参与活动id" prop="participateId">
          <el-input v-model="form.participateId" placeholder="参与活动id自动生成，不必填写" readonly/>
        </el-form-item>
        <el-form-item label="活动id" prop="activityId">
          <el-input v-model="form.activityId" placeholder="请输入活动id" />
        </el-form-item>
        <el-form-item label="活动名称" prop="activityName">
          <el-input v-model="form.activityName" placeholder="请输入活动名称"/>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入用户昵称"/>
        </el-form-item>
        <el-form-item label="报名时间" prop="applyTime">
          <el-date-picker clearable v-model="form.applyTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择报名时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="参与地点" prop="participatePosition">
          <el-input v-model="form.participatePosition" placeholder="请输入参与地点"/>
        </el-form-item>
        <el-form-item label="打卡图片" prop="punchingImg">
          <image-activityImg-upload v-model="form.punchingImg" />
        </el-form-item>
        <el-form-item label="参与时间" prop="participateTime">
          <el-date-picker clearable v-model="form.participateTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择参与时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="获得减碳量" prop="reduceCo2">
          <el-input v-model="form.reduceCo2" placeholder="请输入获得的减碳量" />
        </el-form-item>
        <el-form-item label="获得积分" prop="earnPoints">
          <el-input v-model="form.earnPoints" placeholder="请输入获得积分" />
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <template slot="label">
            <span>
              删除标识
              <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.isDel" placeholder="请输入删除标识（0-正常，1-停用）" />
        </el-form-item>
        <!--        <el-form-item label="扩展字段1" prop="ext1">-->
        <!--          <el-input v-model="form.ext1" placeholder="请输入扩展字段1" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="openView" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="参与活动id" prop="participateId">
          <el-input v-model="form.participateId" placeholder="参与活动id自动生成，不必填写" readonly/>
        </el-form-item>
        <el-form-item label="活动id" prop="activityId">
          <el-input v-model="form.activityId" placeholder="未填入活动id" readonly/>
        </el-form-item>
        <el-form-item label="活动名称" prop="activityName">
          <el-input v-model="form.activityName" placeholder="未填入活动名称" readonly/>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="未填入用户id" readonly/>
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="form.nickName" readonly/>
        </el-form-item>
        <el-form-item label="报名时间" prop="applyTime">
          <el-date-picker clearable v-model="form.applyTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="未填入报名时间" readonly>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="参与地点" prop="participatePosition">
          <el-input v-model="form.participatePosition" placeholder="未填入参与地点" readonly/>
        </el-form-item>
        <el-form-item label="打卡图片" prop="punchingImg">
          <template slot-scope="scope">
            <p v-if="form.punchingImg == null">无图片</p>
            <image-preview v-if="form.punchingImg != null" :src="form.punchingImg" :width="50" :height="50" />
          </template>
        </el-form-item>
        <el-form-item label="参与时间" prop="participateTime">
          <el-date-picker clearable v-model="form.participateTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="未填入参与时间"  readonly>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="未填入备注" readonly/>
        </el-form-item>
        <el-form-item label="获得减碳量" prop="reduceCo2">
          <el-input v-model="form.reduceCo2" placeholder="未填入获得的减碳量" readonly/>
        </el-form-item>
        <el-form-item label="获得积分" prop="earnPoints">
          <el-input v-model="form.earnPoints" placeholder="未填入获得积分" readonly/>
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <template slot="label">
            <span>
              删除标识
              <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.isDel" placeholder="未填入删除标识（0-正常，1-停用）" readonly/>
        </el-form-item>
        <!--        <el-form-item label="扩展字段1" prop="ext1">-->
        <!--          <el-input v-model="form.ext1" placeholder="请输入扩展字段1" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" />-->
        <!--        </el-form-item>-->
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listActivityLogs, getActivityLogs, delActivityLogs, addActivityLogs, updateActivityLogs } from "@/api/system/activityLogs";
//引入用户信息查询
import { getUserInfo } from "@/api/system/userInfo";
//引入活动信息查询
import { getActivity } from "@/api/system/activity";
export default {
  name: "ActivityLogs",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 活动参与记录管理表格数据
      activityLogsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openEdit: false,
      openView: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        activityId: null,
        activityName: null,
        userId: null,
        nickName: null,
        applyTime: null,
        participatePosition: null,
        punchingImg: null,
        participateTime: null,
        remark: null,
        reduceCo2: null,
        earnPoints: null,
        isDel: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询活动参与记录管理列表 */
    async getList() {
      this.loading = true;
      try {
        const response = await listActivityLogs(this.queryParams);
        this.activityLogsList = response.rows;
        this.total = response.total;
      } catch (error) {
        console.error('获取地址列表失败:', error);
      } finally {
        this.loading = false;
      }
    },
    // 取消按钮
    cancel() {
      this.openEdit = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        participateId: null,
        activityId: null,
        activityName: null,
        userId: null,
        nickName: null,
        applyTime: null,
        participatePosition: null,
        punchingImg: null,
        participateTime: null,
        remark: null,
        reduceCo2: null,
        earnPoints: null,
        isDel: null,
        createTime: null,
        updateTime: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.participateId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openEdit = true;
      this.title = "添加活动参与记录管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const participateId = row.participateId || this.ids
      getActivityLogs(participateId).then(response => {
        this.form = response.data;
        this.openEdit = true;
        this.title = "修改活动参与记录管理";
      });
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.openView = true;
      this.form = row;
      this.title = "查看活动参与记录管理（如需修改，请通过修改按钮进行修改）";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.participateId != null) {
            updateActivityLogs(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openEdit = false;
              this.getList();
            });
          } else {
            addActivityLogs(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openEdit = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const participateIds = row.participateId || this.ids;
      this.$modal.confirm('是否确认删除活动参与记录管理Id为"' + participateIds + '"的数据项？').then(function () {
        return delActivityLogs(participateIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/activityLogs/export', {
        ...this.queryParams
      }, `activityLogs_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
